package com.biz;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.common.GlobalVariables;
import com.dao.IndeximgDao;

@Service("indeximgBiz")
public class IndeximgBiz {
	@Resource(name="indeximgDao")
	private IndeximgDao indeximgDao;
	
	/**
	 * ͨ����� ��ѯ ͼƬ
	 * @param paramStr
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public List searchIndeximg(Map pmap){
		 return indeximgDao.searchIndeximg(pmap);
	}
	
	
	/**
	 * ��ѯͼƬ ������
	 * @param pmap
	 */
	public int searchIndeximgCount(Map pmap) {
		return indeximgDao.searchIndeximgCount(pmap);
	}
	
	/**
	 *  ���� ͼƬ
	 * @param paramStr
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public int addIndeximg(Map pmap){
		return indeximgDao.addIndeximg(pmap);
	}
	
	/**
	 *  ɾ�� ͼƬ
	 * @param id
	 * @return
	 */
	public int deleteIndeximg(String id){
		return indeximgDao.deleteIndeximg(id);
	}
	
	/**
	 *  ɾ�� ѡ��ͼƬ
	 * @param id
	 * @return
	 */
	@Transactional(rollbackFor = Exception.class)
	public int deleteSelectIndeximg(String id) {
		String[] idArray=id.split(",");
		int resultCount=0;
		for(int i=0;i<idArray.length;i++){
			resultCount+=	indeximgDao.deleteIndeximg(idArray[i]);
		}
		return resultCount;
	}
	/**
	 * ���� ͼƬ����
	 * @param paramStr
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public int updateIndeximgClounm(Map pmap){
		return indeximgDao.updateIndeximgClounm(pmap);
	}
	
	/**
	 * ͼƬ����
	 * @param paramStr
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public Map detailsIndeximg(String id){
		return indeximgDao.detailsIndeximg(id);
	}
	
	
	/**
	 * ���� ͼƬ 
	 * @param pmap
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public int updateIndeximg(Map pmap){
		return indeximgDao.updateIndeximg(pmap);
	}
	
	/**
	 * �ؼ�������
	 */
	public Map findIndeximg(String search){		
		List list=indeximgDao.findIndeximg(" and keywords LIKE '%"+search+"%' ");
		Map map=new HashMap();
		StringBuffer zixun = new StringBuffer();
		String fastener="���������ڵ�λ�ã�<a href='index.html' >��ҳ</a>>><a'>�����б�</a>";
		if(list.size()>0){
			zixun.append("<ul>");
			for(int i=0;i<list.size();i++){
				Map map1=(Map) list.get(i);
				zixun.append("<li><a class='press_title' href='as/"+map1.get("id")+".html'>"+map1.get("title")+"</a><a class='press_content'>"+map1.get("content").toString()+"</a></li>");
			}
			zixun.append("</ul>");
		}else{
			zixun.append("û��������ͼƬ");
		}
		map.put("weizhi", fastener);
		map.put("zixun", zixun);
		return map;				
	}
	/**
	 * ͨ��˵�ID��ѯ����
	 */
	public int menuIdCount(String menuIdCount){
		String sql="";
		if(Integer.valueOf(GlobalVariables.caidan.get(menuIdCount).toString())==0){
			sql=" and pmenuid="+menuIdCount+"";
		}else{
			sql=" and cmenuid="+menuIdCount+"";
		}
		return indeximgDao.menuIdCount(sql);		
	}
}
